from typing import List
from pydantic_settings import BaseSettings, SettingsConfigDict

class Settings(BaseSettings):
    model_config = SettingsConfigDict(
        env_file='.env',
        case_sensitive=True,
        extra='allow'  # 允许额外的配置项
    )

    # App Settings
    PROJECT_NAME: str
    VERSION: str
    API_V1_STR: str

    # Server Settings
    HOST: str
    PORT: int
    RELOAD: bool
    DEBUG: bool
    LOG_LEVEL: str

    # Database Settings
    DB_HOST: str
    DB_PORT: int
    DB_USER: str
    DB_PASS: str
    DB_NAME: str
    DB_CHARSET: str = "utf8mb4"
    DB_POOL_SIZE: int = 20
    DB_POOL_RECYCLE: int = 3600

    @property
    def DATABASE_URL(self) -> str:
        return (
            f"mysql+pymysql://{self.DB_USER}:{self.DB_PASS}@"
            f"{self.DB_HOST}:{self.DB_PORT}/{self.DB_NAME}"
            f"?charset={self.DB_CHARSET}"
        )

    # Security Settings
    SECRET_KEY: str
    ALGORITHM: str
    ACCESS_TOKEN_EXPIRE_MINUTES: int
    ALLOW_CREDENTIALS: bool = True

    # WeChat Settings
    WECHAT_APP_ID: str
    WECHAT_APP_SECRET: str

    # CORS Settings
    CORS_ORIGINS: List[str]
    CORS_METHODS: List[str]
    CORS_HEADERS: List[str]

    # Logging Settings
    LOG_FORMAT: str
    LOG_FILE: str
    ERROR_LOG_FILE: str

settings = Settings() 